﻿    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.17&key=AIzaSyAzis5t_l_u5RMnW1MqjPO8VBlo2s6hqds">

    </script>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?language=vn"></script>
    <script>
        
        function initialize() {
            var mapOptions = {
                zoom: 15,
                center: new google.maps.LatLng(16.054840, 108.200298)
            };

            map = new google.maps.Map(document.getElementById('map-canvas'),
                mapOptions);


            google.maps.event.addListener(map, 'click', function (e) {
                placeMarker(e.latLng, map);
            });

            function placeMarker(position, map) {
                var marker = new google.maps.Marker({
                    position: position,
                    map: map
                });

                //alert("Chao"+position);

                google.maps.event.addListener(marker, 'click', function (e) {
                    //var infowindow = new google.maps.InfoWindow({
                    //    content: "" + position
                    //});
                    //infowindow.open(marker.get('map'), marker);
                    //alert(marker.getPosition());
                    //alert()
                    var latLng = e.latLng;
                    lat = latLng.lat();
                    lng = latLng.lng();
                    $("#PointX").val(lat);
                    $("#PointY").val(lng);
                    alert(lat + "  " + lng);

                });

            }
        }

        function getCurrent()
        {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function (position) {
                    var pos = new google.maps.LatLng(position.coords.latitude,
                                                     position.coords.longitude);

                    //var infowindow = new google.maps.InfoWindow({
                    //    map: map,
                    //    position: pos,
                    //    content: 'Location found using HTML5.'
                    //});
                    $("#PointX").val(position.coords.latitude);
                    $("#PointY").val(position.coords.longitude);
                    new google.maps.Marker({ position: pos, map: map });
                    map.setCenter(pos);
                }, function () {
                    handleNoGeolocation(true);
                });
            } else {
                // Browser doesn't support Geolocation
                handleNoGeolocation(false);
            }
        }

        function showPointOnMap(x, y) {
            alert(x + ' ' + y);

            var pos = new google.maps.LatLng(x, y);
            new google.maps.Marker({ position: pos, map: map });
            map.setCenter(pos);
            
            //var mapOptions = {
            //    zoom: 4,
            //    center: myLatlng
            //}
            //var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

            //var marker = new google.maps.Marker({
            //    position: myLatlng,
            //    map: this.map,
            //    title: 'Hello World!'
            //});

        }

        function handleNoGeolocation(errorFlag) {
            if (errorFlag) {
                var content = 'Error: The Geolocation service failed.';
            } else {
                var content = 'Error: Your browser doesn\'t support geolocation.';
            }

            var options = {
                map: map,
                position: new google.maps.LatLng(60, 105),
                content: content
            };

            var infowindow = new google.maps.InfoWindow(options);
            map.setCenter(options.position);
        }
        google.maps.event.addDomListener(window, 'load', initialize);

    </script>